/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * <p>Project: jse2204 - Stream2
 * <p>Powered by webrx On 2022-09-28 15:51:42
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Stream2 {
    public static void main(String[] args) {
        //boxed() limit() generate() toList() stream() filter() distinct() map() skip()
        Stream<Integer> ss = IntStream.generate(() -> new Random().nextInt(1, 101)).limit(10).boxed();
        List<Integer> list = ss.toList();
        System.out.println(list);

        ss = list.stream().skip(3).limit(45);

        //ss.sorted().forEach(System.out::println); 升序

        //ss.sorted((a,b)->b-a).forEach(System.out::println); 降序

        List<Integer> list2 = new ArrayList<>(ss.toList());
        Collections.shuffle(list2);
        list2.forEach(System.out::println);


        //var s2 = ss.filter(e -> e % 2 == 0).distinct().map(e -> e * e);
        //s2.forEach(System.out::println);

        //peek() 方法
        //s2.peek(e->System.out.print(2*2 + "\n")).forEach(System.out::println);


        //流的终止操作.count() 方法
        //System.out.println(ss.count());

        //流的终止操作 .forEach() 方法
        //ss.forEach(System.out::println);


    }
}
